package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
@Slf4j
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    //分页多表查询，条件护理项目名称，状态,创建时间,结束时间
    @GetMapping
    @ApiOperation(value = "分页查询护理项目信息")
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(@ApiParam(value = "护理项目名称") @RequestParam(required = false) String name,
                                                                       @ApiParam(value = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
                                                                       @ApiParam(value = "每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
                                                                       @ApiParam(value = "状态") @RequestParam(required = false) Integer status) {
        PageResponse<NursingProjectVo> page = nursingProjectService.selectByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(page);
    }

    //查询所有护理项目
    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目信息")
    public ResponseResult<List<NursingProjectVo>> selectAll() {
        List<NursingProjectVo> all = nursingProjectService.selectAll();
        return ResponseResult.success(all);
    }


    //新增护理项目信息
    @PostMapping()
    @ApiOperation(value = "新增护理项目信息")                     //多表未完成
    public ResponseResult create(@RequestBody NursingProject nursingProject) {
        log.info("新增护理项目信息：{}", nursingProject);
        nursingProjectService.create(nursingProject);
        return ResponseResult.success();
    }


    //根据id查询护理
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目信息")
    public ResponseResult<NursingProjectVo> read(@PathVariable("id") Long id) {
        NursingProject nursingProject = nursingProjectService.read(id);
        return ResponseResult.success(nursingProject);
    }

    //根据id修改护理项目信息
    @PutMapping()
    @ApiOperation(value = "根据id修改护理项目信息")                  //多表未完成
    public ResponseResult update(@RequestBody NursingProject nursingProject) {
        log.info("修改护理项目信息：{}", nursingProject);
        nursingProjectService.update(nursingProject);
        return ResponseResult.success();
    }

    //启用禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用护理项目信息")
    public ResponseResult updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        log.info("修改护理项目信息状态：{}", status);
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }


    //根据id删除护理项目信息
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除护理项目信息")
    public ResponseResult delete(@PathVariable("id") Long id) {
        log.info("删除护理项目信息：{}", id);
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }


}
